package uitls;



import org.apache.http.HttpResponse;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

/**
 * @Author wuchao66
 * @Date 2023/6/13 16:48
 * @PackageName:com.wuchao.utilrl
 * @ClassName: T1
 * @Description: TODO
 * @Param
 * @Version 1.0
 */
public class T1 {
    public static void main(String[] args) {
        //手机号码 +验证码
        String host = "http://edisim.market.alicloudapi.com";
        String path = "/comms/sms/groupmessaging";
        String method = "POST";
        String appcode = "6752ec311a2a4066862ad4a3b374c1dc";
        //封装请求
        Map<String, String> headers = new HashMap<String, String>();
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + appcode);
        //根据API的要求，定义相对应的Content-Type
        headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
        Map<String, String> querys = new HashMap<String, String>();
        Map<String, String> bodys = new HashMap<String, String>();
        bodys.put("callbackUrl", "http://www.esandinfo.com/sms/notify");
        bodys.put("mobileSet", "[8615307413463,8619165615618]");
        bodys.put("templateID", "20230414140359");
        int num= new Random().nextInt(900000)+100000;
        String y=String.format("%s,%s",num,3);
        //String x=String.format("%s,%s",num,5);
       // String y= MessageFormat.format("{0}{1}");
       bodys.put("templateParamSet", y);
        //bodys.put("templateParamSet", x);
        System.out.println(y);

        try {
            /**
             * 重要提示如下:
             * HttpUtils请从
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
             * 下载
             *
             * 相应的依赖请参照
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
             */
           // HttpUtils.
            HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
           System.out.println(response.toString());
            //获取response的body
            //System.out.println(EntityUtils.toString(response.getEntity()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
